package com.example.nettyparseinner.future;

import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.Callable;

/**
 * author :sherlock.lin
 * date : Created in 2023/2/9
 * description :
 */
public class TestNettyFuture {
    private static final Logger LOG = LoggerFactory.getLogger(TestNettyFuture.class);

    public static void main(String[] args) throws Exception{
        NioEventLoopGroup group = new NioEventLoopGroup();
        EventLoop eventLoop = group.next();
        Future<Integer> future = eventLoop.submit(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                LOG.debug("执行计算");
                Thread.sleep(2000);
                return 1024;
            }
        });

//        LOG.debug("等待结果");
//        LOG.debug("结果是 {}", future.get());
        future.addListener(new GenericFutureListener<Future<? super Integer>>() {
            @Override
            public void operationComplete(Future<? super Integer> future) throws Exception {
                LOG.debug("接收结果是:{}", future.getNow());
            }
        });
    }

}
